<?php

namespace Vanthink\Wordbank\Providers;

use Illuminate\Support\ServiceProvider;
use Vanthink\Wordbank\Helper\PhoneticCollectionHelper;

class WechatServiceProvider extends ServiceProvider
{
    /**
     * Bootstrap the application services.
     *
     * @return void
     */
    public function boot()
    {
        // 发布配置文件
        if (!file_exists(config_path('vanthinkWordbankPhoneticConfig.php'))) {
            $this->publishes([
                __DIR__.'/config/vanthinkWordbankPhoneticConfig.php' => config_path('vanthinkWordbankPhoneticConfig.php'),
            ], 'config');
        }
    }

    /**
     * Register the application services.
     *
     * @return void
     */
    public function register()
    {
        $this->mergeConfigFrom( __DIR__.'/../config/vanthinkWordbankPhoneticConfig.php', 'vanthinkWordbankPhoneticConfig');
        $this->app->singleton('vanthinkWordbankPhonetic', function ($app) {
            $config = $app->make('config');
            return new PhoneticCollectionHelper($config->get('vanthinkWordbankPhoneticConfig.phonetic_url'));
        });
    }
}
